﻿#region << 文 件 说 明 >>
/*----------------------------------------------------------------
// 文件名称：AddOrEditModelEditViewModel
// 创 建 者：杨程
// 创建时间：2021/9/22 17:56:58
// 文件版本：V1.0.0
// ===============================================================
// 功能描述：
//		
//
//----------------------------------------------------------------*/
#endregion

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using V.CodeGenerator.Model;
using Vampirewal.Core.SimpleMVVM;
using Vampirewal.Core.IoC;
using Vampirewal.Core;
using Vampirewal.Core.Models;

namespace V.CodeGenerator.ViewModel
{
    [VampirewalIoCRegister(ViewModelKey.AddOrEditModelEditViewModel, RegisterType.ViewModel)]
    public class AddOrEditModelEditViewModel:BillVM<ModelEdit>
    {
        public AddOrEditModelEditViewModel()
        {
            //构造函数
        }

        public override void InitData()
        {
            PropType = EnumHelper.EnumToList<PropType>().Where(e => e.Classification >= 1 && e.Classification <= 11).OrderBy(e => e.Classification).ToList();
        }

        public override object GetResult()
        {
            return Entity;
        }


        public override void PassData(object obj)
        {
            //有值就是修改，空值就是新增
            if (obj!=null)
            {
                SetEntity((ModelEdit)obj);

                Title = "修改字段";

                SelectPropType = PropType.Find(f => f.Value == ((int)Entity.propType));
            }
            else
            {
                //SetEntity(new ModelEdit());

                Title = "新增字段";
            }
        }

        #region 属性
        public List<EnumberCreditType> PropType { get; set; }

        private EnumberCreditType _SelectPropType;
        public EnumberCreditType SelectPropType 
        {
            get
            {
                return _SelectPropType;
            }
            set
            {
                _SelectPropType = value;
                DoNotify();
            }
        }
        #endregion

        #region 公共方法

        #endregion

        #region 私有方法

        #endregion

        #region 命令
        public RelayCommand<object> SelectPropTypeCommand => new RelayCommand<object>((s) => 
        {
            Entity.propType = (CodeGenerator.Model.PropType)s;

            switch (s)
            {
                case 0:
                    //选择了字符串
                    IsString = true;
                    IsShortIntLongFloatDoubleDecimal = false;
                    IsFloatDoubleDecimal = false;
                    break;
                case 5:
                case 6:
                case 7:
                    IsShortIntLongFloatDoubleDecimal = true;
                    IsString = false;
                    IsFloatDoubleDecimal = false;
                    break;
                case 8:
                case 9:
                case 10:
                case 11:
                    IsShortIntLongFloatDoubleDecimal = true;
                    IsString = false;
                    IsFloatDoubleDecimal = true;
                    break;
                default:
                    IsShortIntLongFloatDoubleDecimal = false;
                    IsString = false;
                    IsFloatDoubleDecimal = false;
                    break;
            }
        });


        private bool _IsString;

        public bool IsString
        {
            get { return _IsString; }
            set { _IsString = value;DoNotify(); }
        }

        private bool _IsShortIntLongFloatDoubleDecimal;

        public bool IsShortIntLongFloatDoubleDecimal
        {
            get { return _IsShortIntLongFloatDoubleDecimal; }
            set { _IsShortIntLongFloatDoubleDecimal = value; DoNotify(); }
        }

        private bool _IsFloatDoubleDecimal;

        public bool IsFloatDoubleDecimal
        {
            get { return _IsFloatDoubleDecimal; }
            set { _IsFloatDoubleDecimal = value; DoNotify(); }
        }

        #endregion
    }
}
